{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "292b81e9-fdbb-4076-9591-875d4e7a92db",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os \n",
    "import pandas as pd\n",
    "import shutil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1364bb0a-1adc-43b1-9a44-90ddc39e104f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取datasheet信息\n",
    "datasheet_path = r'C:\\Users\\luke_\\Desktop\\[Projects]NaoDao_ClosedBeta_1st'\n",
    "os.chdir(datasheet_path)\n",
    "datasheet = pd.read_excel('DataSheet.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "75521acb-1f57-4c65-9faf-635ea61f62ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取online order1 & order2的被试名单\n",
    "online_order1_data = datasheet[datasheet['线上实验(Pavlovia)']==1]\n",
    "online_order2_data = datasheet[datasheet['线上实验(Pavlovia)']==2]\n",
    "online_order1_name = online_order1_data['被试姓名'].tolist()\n",
    "online_order2_name = online_order2_data['被试姓名'].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3d4f931f-3fc1-4bcf-8b66-bcbaab9a0552",
   "metadata": {},
   "outputs": [],
   "source": [
    "base_path = r'C:\\Users\\luke_\\Desktop\\[Projects]NaoDao_ClosedBeta_1st\\NaoDao_DATA\\OnlineDATA(Pavlovia)'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "eaa01231-1b3c-4d0d-83f3-165a9a7860aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "ori_data_path = f'{base_path}/OriginalDATA'\n",
    "os.chdir(ori_data_path)\n",
    "online_ori_tasklists = os.listdir()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b0ecb079-89fb-4bf1-8c85-72319f70f5a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(0,len(online_ori_tasklists)):\n",
    "    online_task_path = f'{ori_data_path}/{online_ori_tasklists[i]}'\n",
    "    os.chdir(online_task_path)\n",
    "    # make two folders\n",
    "    os.mkdir('csv_file')\n",
    "    os.mkdir('gz_file')\n",
    "    # move files\n",
    "    online_task_filelists = os.listdir()\n",
    "    # remove dir in filelists\n",
    "    online_task_filelists.remove('csv_file')\n",
    "    online_task_filelists.remove('gz_file')\n",
    "    for m in range(0,len(online_task_filelists)):\n",
    "        if '.csv' in online_task_filelists[m]:\n",
    "            shutil.move(online_task_filelists[m], 'csv_file')\n",
    "        elif '.gz' in online_task_filelists[m]:\n",
    "            shutil.move(online_task_filelists[m], 'gz_file')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0b64b111-8b54-4de9-b7d4-2abe95182603",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(0,len(online_ori_tasklists)):\n",
    "    online_task_csv_path = f'{ori_data_path}/{online_ori_tasklists[i]}/csv_file'\n",
    "    os.chdir(online_task_csv_path)\n",
    "    csv_filelist = os.listdir()\n",
    "    # order1/2 folder path\n",
    "    order1_base_path = r'C:\\Users\\luke_\\Desktop\\[Projects]NaoDao_ClosedBeta_1st\\NaoDao_DATA\\OnlineDATA(Pavlovia)\\Order1'\n",
    "    order2_base_path = r'C:\\Users\\luke_\\Desktop\\[Projects]NaoDao_ClosedBeta_1st\\NaoDao_DATA\\OnlineDATA(Pavlovia)\\Order2'\n",
    "    order1_folder_path = f'{order1_base_path}/{online_ori_tasklists[i]}'\n",
    "    order2_folder_path = f'{order2_base_path}/{online_ori_tasklists[i]}'\n",
    "    for n in range(0, len(csv_filelist)):\n",
    "        each_csv = pd.read_csv(csv_filelist[n])\n",
    "        parti_name = each_csv['请填写您的姓名：'].iloc[0]\n",
    "        if parti_name in online_order1_name:\n",
    "            shutil.copy(csv_filelist[n],order1_folder_path)\n",
    "        elif parti_name in online_order2_name:\n",
    "            shutil.copy(csv_filelist[n],order2_folder_path)\n",
    "        else:\n",
    "            continue"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
